package zero.tech.games.logic.work.room;

import zero.tech.core.ZeroContext;
import zero.tech.core.data.Resp;
import zero.tech.core.event.service.api.EventService;
import zero.tech.core.work.QueueWork;
import zero.tech.core.work.WorkQueue;
import zero.tech.games.common.Code;
import zero.tech.games.logic.common.Room;
import zero.tech.games.logic.data.LogicEventType;
import zero.tech.games.logic.data.RoomStatus;
import zero.tech.games.logic.data.consts.LOGICCMD;
import zero.tech.games.logic.util.LogicUtil;
import zero.tech.wsnet.data.Message;

public class FreeRoomWork extends QueueWork{
	private Room room;
	@Override
	public void init(Object... objs) throws Exception {
		room=(Room) objs[0];
	}

	@Override
	public void run() {
		int room_status=room.getRoom_status();
		EventService eventService=ZeroContext.getInstance(EventService.class);
		if(room_status>RoomStatus.DEFAULT) {
			//房间关闭,强制解散房间
			eventService.engineNotify(LogicEventType.ROOM_DISSOLUTION_FREE, room);
		}else if(room_status==RoomStatus.DEFAULT) {
			LogicUtil.freeRoom(room,Message.build(LOGICCMD.RES_LEAVE, Resp.build(Code.OK, "强制离开成功")));
		}
	}

	@Override
	public WorkQueue getWorkQueue() {
		return new WorkQueue() {
			@Override
			public long getId() {
				return room.getQueue_id();
			}
		};
	}

}
